<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>async和await语法糖</title>
</head>
<body>
    <script>
        // new Promise((resolve,reject) => {
        //     resolve("成功");
        // }).then(
        //     value => {
        //         return new Promise((resolve,reject) => {
        //             setTimeout(() => {
        //                 console.log(value);
        //                 reject("失败");
        //             },2000)
        //         })
        //     }
        // ).then(
        //     null,
        //     reason => {
        //         setTimeout(() => {
        //             console.log(reason);
        //         },2000)
        //     }
        // )


        // async相当于实例化一个promise，await相当于then，await后面是返回的值
        // await必须放在async中使用，否则会报语法错误 
        // async function hd(){
        //     let name = await "hdms";
        //     console.log(name);
        //     return new Promise((resolve,reject) => {
        //         resolve("success");
        //     })
        // }

        // hd().then(
        //     value => {
        //         console.log(value);
        //     }
        // )



        async function hdms(){
            let name = await new Promise((resolve,reject) => {
                setTimeout(() => {
                    resolve("后盾人");
                },2000)
            });
            console.log(name);
            let site = await new Promise((resolve,reject) => {
                setTimeout(() => {
                    console.log();
                    resolve(name + "houdunren");
                },2000)
            });
            console.log(site);
        }
        hdms();
    </script>
</body>
</html>